package cn.billy._02_async;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Producer {
    public static void main(String[] args) throws Exception {
        // 创建生产者，创建组名
        DefaultMQProducer producer = new DefaultMQProducer("async_hello_producer");
        // 连接NamesrvAddr
        producer.setNamesrvAddr("127.0.0.1:9876");
        // 启动生成者
        producer.start();
        // 创建消息题
        Message message = new Message("async", "hello", "小贾是我幺儿".getBytes(StandardCharsets.UTF_8));
        // 发送消息
        producer.send(message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println("发送消息成功！");
            }

            @Override
            public void onException(Throwable throwable) {
                System.out.println("发送消息失败！");
            }
        });
         // producer.shutdown();

    }
}
